package com.dd.cloud.user.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dd.cloud.user.req.log.LogExceptionPageReq;
import com.dd.cloud.user.req.log.OperLogPageReq;
import com.dd.cloud.user.res.log.LogExceptionPageRes;
import com.dd.cloud.user.res.log.OperLogPageRes;
import com.dd.cloud.user.service.log.ILogExceptionService;
import com.dd.cloud.user.service.log.ILogModulService;
import com.dd.cloud.user.service.log.ILogOperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
 * <p>
 * 操作日志 前端控制器
 * </p>
 *
 * @author czg
 * @since 2022-04-27
 */
@RestController
@RequestMapping("/log")
public class LogController {
    @Autowired
    private ILogOperService logOperService;
    @Autowired
    private ILogExceptionService logExceptionService;
    @Autowired
    private ILogModulService logModulService;

    /**
     * 查询操作日志分页
     *
     * @param req
     * @return
     */
    @GetMapping("/oper/page/system")
    public ResponseEntity<IPage<OperLogPageRes>> queryOperLogPage(@Valid OperLogPageReq req) {
        IPage<OperLogPageRes> res = logOperService.queryOperLogPage(req);
        return ResponseEntity.ok(res);
    }

    /**
     * 查询异常日志记录
     *
     * @param req
     * @return
     */
    @GetMapping("/exception/page/system")
    public ResponseEntity<IPage<LogExceptionPageRes>> queryLogExceptionPage(@Valid LogExceptionPageReq req) {
        IPage<LogExceptionPageRes> res = logExceptionService.queryLogExceptionPage(req);
        return ResponseEntity.ok(res);
    }

    /**
     * 导入日志模板信息
     *
     * @param file
     */
    @PostMapping("/modul/excel/import")
    public ResponseEntity<Void> importLogModul(@NotNull(message = "文件不能为空") MultipartFile file) {
        logModulService.importLogModul(file);
        return ResponseEntity.ok().build();
    }
}

